import anylogger from 'anylogger';
import { GetServerSideProps, NextPage, PageConfig } from 'next';
import Head from 'next/head';
import Content from './content';
import { Query as Q1 } from '../../api/class/add/query.api';

const logger = anylogger('pages/class/add/index.page');

interface IProps {
	query: Q1;
	id: string;
}

/**
 * 班级成员管理
 */
const Page: NextPage<IProps> = ({ query, id }) => {
	return (
		<>
			<Head>
				<title>成员添加</title>
			</Head>
			<Content initialquery={query} id={id} />
		</>
	);
};

export const config: PageConfig = {
	amp: false
};

export default Page;

// pre-render this page on each request
export const getServerSideProps: GetServerSideProps<IProps> = async (context) => {
	const query = context.query as Record<string, string>;
	if (!query.id) {
		logger.error('id is empty');
	}
	return {
		props: {
			query: {
				page: query.page || '1',
				pagesize: '10',
				q: query.q || '',
				id: query.id || ''
			},
			id: query.id || ''
		}
	};
};

